package com.example.spiarch

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import com.example.base.ILogin
import com.example.base.IPay
import com.example.spiarch.databinding.ActivityMainBinding
import java.util.ServiceLoader

class MainActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val activityMainBinding = ActivityMainBinding.inflate(LayoutInflater.from(this))
        setContentView(activityMainBinding.root)

        activityMainBinding.login.setOnClickListener {
            val loader = ServiceLoader.load(ILogin::class.java)
            val iterator = loader.iterator()
            while (iterator.hasNext()) {
                val iLogin = iterator.next()
                iLogin.login("yangzhi", "123456")
            }
        }

        activityMainBinding.signup.setOnClickListener {
            val loader = ServiceLoader.load(IPay::class.java)
            val iterator = loader.iterator()
            while (iterator.hasNext()) {
                val iPay = iterator.next()
                iPay.payMoney(1, 100)
            }
        }
    }
}